package com.xiaoma.springbootannotation.controller;

import com.xiaoma.springbootannotation.annotation.CheckCommit;
import com.xiaoma.springbootannotation.annotation.RedisAndLua;
import com.xiaoma.springbootannotation.annotation.Redisson;
import com.xiaoma.springbootannotation.annotation.SystemLogger;
import com.xiaoma.springbootannotation.demo.HandlerChain;
import com.xiaoma.springbootannotation.demo.entity.Request;
import com.xiaoma.springbootannotation.demo.entity.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: xiaoma
 * @Date: 2021/8/10 9:58
 * @description:
 */
@RestController
@Slf4j
public class SysLogController {
    @Resource
    private HandlerChain handlerChain;

    @RequestMapping("/hello")
    @SystemLogger(type = "系统日志")
    @CheckCommit
    public void hello() {
    }

    @RequestMapping("/commit/{name}")
    @SystemLogger(type = "个人日志")
    @CheckCommit(expireTime = 12000)
    public void commit(@PathVariable("name") String name) throws InterruptedException {
    }

    @RequestMapping("/seckill/{name}")
    @Redisson
    public void secKill(@PathVariable("name") String name) throws InterruptedException {
        log.info("线程" + Thread.currentThread().getName() + "==========正在秒杀============");
        Thread.sleep(6000);
    }

    @RequestMapping("/seckill2/{name}")
    @RedisAndLua(expireTime = 30000)
    public void redisAndLua(@PathVariable("name") String name) throws InterruptedException {
        log.info("线程" + Thread.currentThread().getName() + "==========正在秒杀============");
        Thread.sleep(6000);
    }
    @RequestMapping("/test/{str}")
    public void y(@PathVariable String str) {
        handlerChain.doFilter(new Request(str),new Response());
    }
}
